package cn.idietrade.idietradegoodsmodule8002.service.imgservice.impl;

import cn.idietrade.common.pojo.SecondImg;
import cn.idietrade.idietradegoodsmodule8002.mapper.SecondImgMapper;
import cn.idietrade.idietradegoodsmodule8002.service.imgservice.SecondImgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zjy
 * @version 1.0
 * @createTime 2022-12-09 15:54
 * @description
 */
@Service
public class SecondImgServiceImpl implements SecondImgService {
    @Resource
    private SecondImgMapper secondImgMapper;

    @Override
    public int addImg(SecondImg secondImg) {
        return secondImgMapper.addImg(secondImg);
    }

    @Override
    public PageInfo<SecondImg> queryImgAll(Integer pageNum, Integer pageSize,Integer goodsId) {
        if(pageNum==null||pageNum<=1){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=4;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<SecondImg> pageInfo=new PageInfo<>(secondImgMapper.queryImgAll(goodsId));
        return pageInfo;
    }

    @Override
    public int updataImg(Integer goodsId,String ids) {
        String[] split = ids.split(",");
        List<Integer> list =new ArrayList<>();
        for (String s : split) {
            list.add(Integer.valueOf(s));
        }

        return secondImgMapper.updataImg(goodsId,list);
    }
}
